package com.ruoyi.cderp.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cderp.domain.ProductionPicking;
import com.ruoyi.cderp.service.IProductionPickingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产领料Controller
 *
 * @author wzy
 * @date 2025-06-11
 */
@RestController
@RequestMapping("/system/ProductionPicking")
public class ProductionPickingController extends BaseController
{
    @Autowired
    private IProductionPickingService productionPickingService;

    /**
     * 查询生产领料列表
     */
    @PreAuthorize("@ss.hasPermi('system:ProductionPicking:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductionPicking productionPicking)
    {
        startPage();
        List<ProductionPicking> list = productionPickingService.selectProductionPickingList(productionPicking);
        return getDataTable(list);
    }


    /**
     * 新增时查询关于生产工单的相关数据
     */
    @PreAuthorize("@ss.hasPermi('system:ProductionPicking:query')")
    @GetMapping("/query")
    public AjaxResult getInfoList(
            @RequestParam String id
    )
    {
        return success(productionPickingService.selectOrderPickingList(id));
    }




    /**
     * 导出生产领料列表
     */
    @PreAuthorize("@ss.hasPermi('system:ProductionPicking:export')")
    @Log(title = "生产领料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductionPicking productionPicking)
    {
        List<ProductionPicking> list = productionPickingService.selectProductionPickingList(productionPicking);
        ExcelUtil<ProductionPicking> util = new ExcelUtil<ProductionPicking>(ProductionPicking.class);
        util.exportExcel(response, list, "生产领料数据");
    }

    /**
     * 获取生产领料详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ProductionPicking:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(productionPickingService.selectProductionPickingById(id));
    }

    /**
     * 新增生产领料
     */
    @PreAuthorize("@ss.hasPermi('system:ProductionPicking:add')")
    @Log(title = "生产领料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductionPicking productionPicking)
    {
        return toAjax(productionPickingService.insertProductionPicking(productionPicking));
    }

    /**
     * 修改生产领料
     */
    @PreAuthorize("@ss.hasPermi('system:ProductionPicking:edit')")
    @Log(title = "生产领料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductionPicking productionPicking)
    {
        return toAjax(productionPickingService.updateProductionPicking(productionPicking));
    }

    /**
     * 删除生产领料
     */
    @PreAuthorize("@ss.hasPermi('system:ProductionPicking:remove')")
    @Log(title = "生产领料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(productionPickingService.deleteProductionPickingByIds(ids));
    }
}
